package com.ravi.core.checkup;


import com.ravi.dao.CheckRoomDAO;
import com.ravi.entity.CheckRoom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class CheckingUpManager {

	public static final ConcurrentHashMap<Integer, CheckingUp> CheckingUpManager = new ConcurrentHashMap<>();

	@Autowired
	private CheckRoomDAO checkRoomDAO;

	/**
	 * 添加队列
	 * @param checkingUp
	 */
	public static void addRoom(CheckingUp checkingUp) {
		CheckingUpManager.put(checkingUp.getCheckRoom().getRoomId(), checkingUp);
	}

	public static CheckingUp getRoom(Integer roomId) {
		return CheckingUpManager.get(roomId);
	}

	@PostConstruct
	public void init() {
		List<CheckRoom> checkRooms = checkRoomDAO.getAllCheckRooms();
		CheckingUp checkingUp = null;
		for (CheckRoom room : checkRooms) {
			checkingUp = new CheckingUp(room);
			addRoom(checkingUp);
		}
	}

	@PreDestroy
	public void destroy() {
		//系统运行结束
	}
}
